import { createRouter, createWebHistory } from "vue-router";

const routes = [
  {path: '/',name:'Index',title:'首页',component:()=>import("@/views/index.vue")},
  {path: '/zhengce',name:'Zhengce',title:'政策法规',component:()=>import("@/views/zhengce.vue")},
  {path: '/zcdetail',name: 'zhengceDetail',title: '政策法规详情',component: () => import('@/views/zhengceDetail.vue')},
  {path: '/pingtai',name:'Pingtai',title:'平台',component:()=>import("@/views/pingtai.vue")},
  {path: '/ptdetail',name:'Detail',title:'动态详情',component:()=>import("@/views/pingtaiDetail.vue")},
  {path: '/complaints', name: 'complaints',title: '违规投诉',component: () => import('@/views/complaints.vue')},
  {path: '/cdetail',name: 'complaintsDetail',title: '违规投诉详情', component: () => import('@/views/complaintsDetail.vue')},
  {path: '/information', name:'Information',title:'信息公告',component:()=>import("@/views/information.vue")},
  {path: '/Detail_page/:id', name:'Detail_page',title:'信息公告详细页',component:()=>import("@/views/Detail_page.vue")}, 
  {path: '/Personal_Center', name:'Personal_Center',title:'个人中心',component:()=>import("@/views/Personal_Center.vue")},  
  {path: '/enterprise', name:'Enterprise',title:'企业信息',component:()=>import("@/views/enterprise.vue")},
  {path: '/404',component:()=>import("@/views/NotFound.vue")},
  {path:'/:pathMatch(.*)*',redirect:'/404' }
]

const router = createRouter({
  history: createWebHistory(),routes,
})

router.beforeEach((to, from, next) => {
  if (to.path === '/person' && !store.isLoggedIn) { 
    next({
      path: '/login',
      query: { redirect: to.fullPath } 
    });
  } else {
    next();
  }
})

export default router;